home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
WDFTST__
/
DIALOGS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-06-12
|
5KB
|
201 lines
#include <stdio.h>
#include <stdarg.h>
#include <MacProto.h>
#include "proto.h"
#include "defines.h"
#include "external_globals.h"
#include "TextDisplay.h"
int g_grow_icon_choice;
pascal Boolean Dialog_filter( DialogPtr the_dialog,
EventRecord *the_event,
int *item_number );
ControlHandle Get_Ditem_handle( DialogPtr theDialog, int item_no );
void Tune_radio( DialogPtr what_dialog, int on_button, ...);
/* ------------------------- Handle_grow_choice ----------------------- */
void Handle_grow_choice()
{
DialogPtr grow_dlog;
int item_type;
Rect item_box;
int item_hit;
int t_choice;
Boolean alldone;
grow_dlog = GetNewDialog( GROW_ICON_DLOG_ID, nil, (WindowPtr)-1L );
Tune_radio( grow_dlog, g_grow_icon_choice, grow_clipped,
grow_standard, grow_none, 0 );
TD_activate( g_event_window, FALSE );
ShowWindow( grow_dlog );
alldone = FALSE;
t_choice = g_grow_icon_choice;
while (!alldone)
{
ModalDialog( (ProcPtr)Dialog_filter, &item_hit );
switch( item_hit )
{
case grow_ok:
alldone = TRUE;
break;
case grow_cancel:
alldone = TRUE;
break;
case grow_clipped:
case grow_standard:
case grow_none:
t_choice = item_hit;
Tune_radio( grow_dlog, t_choice, grow_clipped,
grow_standard, grow_none, 0 );
break;
}
}
DisposDialog( grow_dlog );
if (item_hit == grow_ok)
{
g_grow_icon_choice = t_choice;
SetPort( g_first_window );
InvalRect( &thePort->portRect );
SetPort( g_second_window );
InvalRect( &thePort->portRect );
}
}
/* --------------------- Get_Ditem_handle -------------------------- */
ControlHandle
Get_Ditem_handle( DialogPtr theDialog, int item_no )
{
int item_type;
Rect box;
Handle item_handle;
GetDItem( theDialog, item_no, &item_type, &item_handle, &box );
return( (ControlHandle) item_handle );
}
/* ----------------------- Tune_radio ----------------------- */
/*
* Switch one radio button on and some others off.
* Input: a handle to the dialog, the item number of the button
* to turn on, a list of item numbers for buttons to turn off,
* and a zero to terminate the list. The "on" button isn't turned
* on until the end, so if the first item also occurs later on
* the list, it will end up turned on. Thus, to reset a radio
* group, you can list the entire group after the first item.
*/
void
Tune_radio( DialogPtr what_dialog, int on_button, ...)
{
va_list arg_ptr;
ControlHandle button_h;
int off_button;
va_start( arg_ptr, on_button );
while ( (off_button = va_arg(arg_ptr, int)) > 0 )
{
button_h = Get_Ditem_handle( what_dialog, off_button );
SetCtlValue( button_h, (int)FALSE );
}
va_end( arg_ptr );
button_h = Get_Ditem_handle( what_dialog, on_button );
SetCtlValue( button_h, (int)TRUE );
}
/* -------------------------- Handle_title_choice ---------------------- */
typedef enum {
td_ok_item = 1,
td_cancel_item,
td_first_title_item,
td_second_title_item
};
void Handle_title_choice()
{
DialogPtr title_DLOG;
Handle first_item_h, second_item_h;
int item_type, item_hit;
Rect item_box;
Str255 new_first_title, new_second_title;
title_DLOG = GetNewDialog( TITLE_DLOG_ID, nil,
(WindowPtr)MOVE_TO_FRONT );
GetDItem( title_DLOG, td_first_title_item,
&item_type, &first_item_h, &item_box );
SetIText( first_item_h, g_first_window_title );
GetDItem( title_DLOG, td_second_title_item,
&item_type, &second_item_h, &item_box );
SetIText( second_item_h, g_second_window_title );
SelIText( title_DLOG, td_first_title_item, 0, 32767 );
TD_activate( g_event_window, FALSE );
ShowWindow( title_DLOG );
ModalDialog( (ProcPtr)Dialog_filter, &item_hit );
if (item_hit == td_ok_item)
{
GetIText( first_item_h, new_first_title );
GetIText( second_item_h, new_second_title );
Copy_p_string( g_first_window_title, new_first_title );
Copy_p_string( g_second_window_title, new_second_title );
Destroy_windows();
CloseDialog( title_DLOG );
Make_windows();
}
else
CloseDialog( title_DLOG );
}
#define RETURN_KEY 0x24
#define ENTER_KEY 0x4C
#define TILDE_KEY 0x32
#define ESCAPE_KEY 0x35
/* ------------------------- Dialog_filter ------------------------ */
pascal Boolean Dialog_filter( DialogPtr the_dialog,
EventRecord *the_event,
int *item_number )
{
int keycode, charcode;
char the_char;
if (the_event->what != keyDown)
return( FALSE );
keycode = (the_event->message & keyCodeMask) >> 8;
if ( (keycode == RETURN_KEY) || (keycode == ENTER_KEY) )
{
*item_number = 1; /* OK */
return( TRUE );
}
if ( (keycode == TILDE_KEY) || (keycode == ESCAPE_KEY) )
{
*item_number = 2; /* Cancel */
return( TRUE );
}
if (the_event->modifiers & cmdKey)
{
charcode = the_event->message & charCodeMask;
the_char = (char)charcode;
*item_number = ((DialogPeek)the_dialog)->editField + 1; /* current text box */
switch (charcode)
{
case 'x':
DlgCut( the_dialog );
break;
case 'c':
DlgCopy( the_dialog );
break;
case 'v':
DlgPaste( the_dialog );
break;
}
the_event->what = 0; /* Change it to a null event */
return( FALSE );
}
else
return( FALSE ); /* ordinary keystroke */
}